<?php
declare(strict_types=1);

namespace app\validate;

use think\Validate;

class MerchantPaymentConfigValidate extends Validate
{
    protected $rule = [
        'id' => 'require|number',
        'merchant_id' => 'require|number',
        'payment_method' => 'require|in:1,2,3',
        'app_id' => 'requireIf:payment_method,1,2',
        'mch_id' => 'requireIf:payment_method,1',
        'key' => 'requireIf:payment_method,1',
        'cert_path' => 'requireIf:payment_method,1',
        'key_path' => 'requireIf:payment_method,1',
        'v3_key' => 'requireIf:payment_method,1',
        'merchant_private_key' => 'requireIf:payment_method,2',
        'alipay_public_key' => 'requireIf:payment_method,2',
        'status' => 'require|in:1,2'
    ];

    protected $message = [
        'payment_method.require' => '支付方式不能为空',
        'payment_method.in' => '不支持的支付方式',
        'app_id.requireIf' => 'AppID不能为空',
        'mch_id.requireIf' => '商户号不能为空',
        'key.requireIf' => 'API密钥不能为空',
        'cert_path.requireIf' => '证书路径不能为空',
        'key_path.requireIf' => '证书密钥路径不能为空',
        'v3_key.requireIf' => 'APIv3密钥不能为空',
        'merchant_private_key.requireIf' => '商户私钥不能为空',
        'alipay_public_key.requireIf' => '支付宝公钥不能为空',
        'status.require' => '状态不能为空',
        'status.in' => '状态参数错误'
    ];

    // 更新场景
    public function sceneUpdate()
    {
        return $this->only(['merchant_id','payment_method','app_id','mch_id','key','cert_path',
            'key_path','v3_key','merchant_private_key','alipay_public_key']);
    }

    // 设置状态场景
    public function sceneSetStatus()
    {
        return $this->only(['id','status']);
    }
} 